<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="ContentManagers.RoleManagers.AdminManager"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="ContentManagers.Security.Hasher"%>
<%@page import="ContentManagers.Security.Validator"%>
<%@page import="ContentManagers.RoleManagers.AuthenticationManager"%>
<%@page import="ContentManagers.Servlets.ServletAddPM"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="DBConnection.ConnectionFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% //employ temporary session management here
            try{
            boolean check = false;
        
            check = new AuthenticationManager().inSuchDB(2, request, response);
            
            if(check == false)
               new AuthenticationManager().redirectToProperIndex(2, request, response);
            
            else
             {
        %>

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="css/admin_int.css" />
        <script type='text/javascript' src='Javascript/adminjs.js'></script>
        
    </head>
    <body>
       <%@ include file="admin_header.jsp"%>
       <% //Call admin header file. The header contains the links for other pages. %>
        
            
       <div id ="body_wrapper">
           <% //Actual Content of the Index page starts here. %>
      
            <%//@ include file="../default_left_sidebar.jsp" %>
            
            <div id="product_manager_options" class="content_box">
                
            <br>Create New Product Manager
            <form name ="createProductManager" method="post" onsubmit="return validateProductManager()" action="../ServletAddPM">
                <table class="create"><tr><td>Select Manager Type:</td>
                        <td><select name="type">
            <%


                ResultSet rs = new AdminManager().getManagerTypes();

                while(rs.next())
                    {
                   
                    out.println("<option value='"+rs.getString("product_type_id")+"'>" + rs.getString("product_type_name") + " Manager" + "</option>");
                    }

            %>
            </select></td></tr>
                    <tr><td>Username:</td>
                        <td><input class="inputbox" type="text" value="" name="username" autocomplete ="off" onfocus="clearInitial(this, 'Username')"/></td></tr>
                    <Tr><td>Password:</tD>
                        <td><input class="inputbox" type="password" value="" name="password" autocomplete ="off" onfocus="clearInitial(this, 'Password')"/></td></tr>
                    <tr><td>Retype Password:</td>
                        <Td><input class="inputbox" type="password" value="" name="password2" autocomplete ="off" onfocus="clearInitial(this, 'Password')"/></td></tr>
                    <tr><td></td></td><td><input type="submit" name="Submit" value="Submit"/></td></tr></table>
            </form>
             <%
             if(session.getAttribute("m1")!=null) {
             
             if(session.getAttribute("m1").equals("1"))
                out.println("\nInvalid username.\n");
             else if(session.getAttribute("m1").equals("2"))
                out.println("\nInvalid password.\n");
             else if(session.getAttribute("m1").equals("3"))
                out.println("\nInvalid type.\n");
             else if(session.getAttribute("m1").equals("4"))
                out.println("\nProduct manager already exists.\n");
             else if (session.getAttribute("m1").equals("5"))
                out.println("\nError in adding product manager. Please check database connection\n");
             else if (session.getAttribute("m1").equals("6"))
                out.println("\nProduct Manager successfully added to the system.\n");
             
             session.removeAttribute("m1");
             }
             %>

            </div>

             
            <div id="accouting_manager_options" class="content_box">
           
            <br>Create New Accounting Manager
            <form name ="createAccountingManager" method="post" onsubmit="return validateAccountingManager()" action="../ServletAddAM">   
                <table class="create">
                    <tr><td>Username:</td>
                        <td><input class="inputbox" type="text" value="" name="username" autocomplete ="off" onfocus="clearInitial(this, 'Username')"/></td></tr>
                    <tr><Td>Password:</td>
                        <td><input class="inputbox" type="password" value="" name="password" autocomplete ="off" onfocus="clearInitial(this, 'Password')"/></td></tr>
                    <tr><td>Retype Password:</td>
                        <td><input class="inputbox" type="password" value="" name="password2" autocomplete ="off" onfocus="clearInitial(this, 'Password')"/></td></tr>
                    <tr><td></td><td><input type="submit" name="Submit2" value="Submit"/></td></tr></table>
                         </form>
             <%
             if(session.getAttribute("m2")!=null) {
                 
             if(session.getAttribute("m2").equals("1"))
                out.println("\nInvalid username.\n");
             else if (session.getAttribute("m2").equals("2"))
                out.println("\nInvalid password.\n");
             else if (session.getAttribute("m2").equals("3"))
                out.println("\nAccounting manager already exists.\n");
             else if (session.getAttribute("m2").equals("4"))
                out.println("\nError in adding accounting manager. Please check database connection\n");
              else if (session.getAttribute("m2").equals("5"))
                out.println("\nAccounting Manager successfully added to the system.\n");
             
             session.removeAttribute("m2");
             }
             %>  
                
            </div>

                            
           <% //Actual Content of the Index page ends here. %>
       </div>
        
            
       <%@ include file="admin_footer.jsp" %>
       <% //Call default footer file %>
    </body>
</html>

<% }
    }catch(Exception e)
        {   session = request.getSession();
            session.setAttribute("username", "xxxxdefaultxxxx");
            session.setAttribute("sessionID", "xxxxdefaultxxxx");
        
            response.sendRedirect("admin_index.jsp");}
            
%>